package com.syezon.wifikey.setting;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;


import com.syezon.wifikey.R;
import com.syezon.wifikey.analysis.AnalysisHelper;
import com.syezon.wifikey.utils.MarketUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GradeNewDialog extends Dialog {

    @BindView(R.id.iv_close)
    ImageView ivClose;

    private GradeCallBack gradeCallBack;

    public static void showGrade(Context context, GradeCallBack gradeCallBack) {
        GradeNewDialog gradeDialog = new GradeNewDialog(context);
        gradeDialog.setGradeCallBack(gradeCallBack);
        gradeDialog.show();
        GradeConfig.saveLastShowTime();
        GradeConfig.saveLastShowDayInt();
    }

    public GradeNewDialog(final Context context) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉title，在有的手机dialog顶部会出现空白
        setContentView(R.layout.app_setting_pop_grade_new);
        AnalysisHelper.onEvent("Praise_total");
        ButterKnife.bind(this);
        // 设置弹出窗体的宽和高
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        Window window = getWindow();
        window.setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }

    public void setGradeCallBack(GradeCallBack callBack) {
        this.gradeCallBack = callBack;
    }

    @OnClick({R.id.iv_close, R.id.tv_feedback, R.id.tv_market})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_close:
                if (gradeCallBack != null) {
                    gradeCallBack.close();
                }
                dismiss();
                break;
            case R.id.tv_feedback:
                if (gradeCallBack != null) {
                    gradeCallBack.feedback();
                }
                FeedBackActivity.feedBack(getContext());
                AnalysisHelper.onEvent("Praise_advise");
                GradeConfig.saveCanShowGradeDialog(false);
                dismiss();
                break;
            case R.id.tv_market:
                GradeConfig.saveHasEncourage(true);
                GradeConfig.saveCanShowGradeDialog(false);
                MarketUtils.launchAppDetail2(getContext());
                AnalysisHelper.onEvent("Praise_give");
                dismiss();
                break;
        }
    }

    public static interface GradeCallBack {
        void feedback();

        void close();
    }
}
